# 方法一
class Solution:
    def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:
        answer = [[], []]
        dict1, dict2 = defaultdict(int), defaultdict(int)
        for x in nums1:
            dict1[x] += 1
        for y in nums2:
            dict2[y] += 1

        for a in nums1:
            if a not in dict2 and a not in answer[0]:
                answer[0].append(a)
        for b in nums2:
            if b not in dict1 and b not in answer[1]:
                answer[1].append(b)
        return answer

# 集合优化
class Solution:
    def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:
        answer = [[], []]
        set1 = set(nums1)
        set2 = set(nums2)

        for a in set1:
            if a not in set2:
                answer[0].append(a)
        for b in set2:
            if b not in set1:
                answer[1].append(b)
        return answer